function multiply(num1, num2) {
    if (num1 === '0' || num2 === '0') return '0';
    
    let result = '0';
    
    // 从num2的个位开始，逐位与num1相乘
    for (let i = num2.length - 1; i >= 0; i--) {
        let carry = 0;
        let tempResult = '';
        const digit2 = num2[i] - '0';
        
        // 补零（相当于乘以10的n次方）
        for (let j = 0; j < num2.length - 1 - i; j++) {
            tempResult += '0';
        }
        
        // num2的当前位与num1相乘
        for (let j = num1.length - 1; j >= 0; j--) {
            const digit1 = num1[j] - '0';
            const product = digit1 * digit2 + carry;
            tempResult = (product % 10) + tempResult;
            carry = Math.floor(product / 10);
        }
        if (carry > 0) {
            tempResult = carry + tempResult;
        }
        // 将当前结果与总结果相加
        result = addStrings(result, tempResult);
    }
    
    return result;
}

// 字符串相加函数（前面实现过的）
function addStrings(num1, num2) {
    let i = num1.length - 1;
    let j = num2.length - 1;
    let carry = 0;
    let result = '';
    
    while (i >= 0 || j >= 0 || carry > 0) {
        const digit1 = i >= 0 ? num1[i] - '0' : 0;
        const digit2 = j >= 0 ? num2[j] - '0' : 0;
        const sum = digit1 + digit2 + carry;
        
        result = (sum % 10) + result;
        carry = Math.floor(sum / 10);
        
        i--;
        j--;
    }
    
    return result;
}